/*
 * txdnet.cn tonydon
 * by netbeans ide 7.2
 */
package cn.txdnet.txcms.dao;

import cn.txdnet.txcms.domain.TinyCmt;
import cn.txdnet.txcms.dto.PageDTO;
import cn.txdnet.txcms.mapper.TinyCmtMapper;
import cn.txdnet.txcms.query.TinyCmtQuery;
import cn.txdnet.txweb.utils.CollectionUtil;
import java.util.List;
import java.util.Map;

/**
 * 微评DAO
 *
 * @author tangxiaodong
 */
public class TinyCmtDAO extends MybatisBaseDAO {

    /**
     * 保存微评信息
     *
     * @param tc
     * @return
     */
    public int insertTinyCmt(TinyCmt tc) {
        TinyCmtMapper mapper = this.getMapper(TinyCmtMapper.class);
        return mapper.insertTinyCmt(tc);
    }

    /**
     * 批量删除评论
     *
     * @param ida
     * @return
     */
    public int deleteTinyCmt(long[] ida) {
        TinyCmtMapper mapper = this.getMapper(TinyCmtMapper.class);
        return mapper.deleteTinyCmt(ida);
    }

    /**
     * 批量更新发布状态
     *
     * @param m
     * @return
     */
    public int updatePubstate(Map<String, Object> m) {
        TinyCmtMapper mapper = this.getMapper(TinyCmtMapper.class);
        return mapper.updatePubstate(m);
    }

    /**
     * 查询微评
     * @param query
     * @return 
     */
    public PageDTO queryByFactor(TinyCmtQuery query) {
        TinyCmtMapper mapper = this.getMapper(TinyCmtMapper.class);
        query.filter();
        List list = mapper.listByFactor(query);
        if (query.getRownum().intValue() == 0 && CollectionUtil.isNotEmpty(list)) {
            query.setRownum(mapper.countByFactor(query));
        }
        return new PageDTO(list, query.getRownum());
    }
}
